package com.gskj.gulimall.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @ClassName GulimallSessionConfig
 * @Description 自定义Session 信息
 * @Author 康纳
 * @Date 2021-03-20
 */

@Configuration
public class GulimallSessionConfig {

    /**
     * 自定义服务端 返回的Cookie信息
     */
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();

        // 设置 domain用域。使子域也可以访问该Cookie信息
        defaultCookieSerializer.setDomainName("gulimall.com");
        // 自定义 Cookiename
        defaultCookieSerializer.setCookieName("GULISESSION");
        return defaultCookieSerializer;
    }

    /**
     * 自定义 redis 序列化器
     */
    @Bean
    public RedisSerializer springSessionDefaultRedisSerializer() {
        // 使用 JSON格式存储数据格式
        return new GenericJackson2JsonRedisSerializer();
    }
}
